
<div class="layui-body-header">
	<h2>官网管理</h2>
	
</div>
		<div class="layui-card-body">
          
            <!-- <span>所有会员列表</span> -->
            
            <div class="layui-fluid">
	            <div class="layui-card">
		            <div class="layui-card-header">
		            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary downs">
		              <i class="layui-icon">&#x1007;</i>
		              <span>下架官网</span>
		            </button>
		            <button type="button" class="layui-btn layui-btn-sm layui-btn-danger batchDel">
		              <i class="layui-icon">&#xe640;</i>
		              <span>批量删除</span>
		            </button>
		            <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-primary" id="search_hash">
		              <i class="layui-icon">&#xe615;</i>
		            </a>
		          </div>
		          <div class="layui-card-body">
		            <table id="test" lay-filter="test"></table>
		            <script type="text/html" id="bartest">
		              <button class="layui-btn layui-btn-xs" lay-event="detail">编辑</button>
		              <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a> -->
		              <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
		            </script>
		          </div>
	        
	      
	      
	      </div>
      </div>
     </div>

<script type="text/html" id="search_tpl_hash">
  <form class="layui-form" action="">
    <div class="layui-form-item">
      <label class="layui-form-label">会员ID</label>
      <div class="layui-input-block">
        <input type="text" name="memId" id="memId" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">会员姓名</label>
      <div class="layui-input-block">
        <input type="text" name="memName" id="memName" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">选择地址</label>
      <div class="layui-input-block">
        <table class="layui-table fenhuiArea" lay-skin="nob">
			<tbody>
				<tr>
					<td>
						<select name="province" class="province" lay-verify="" lay-filter="provinces"> 
								  <option value="">省份</option>
								</select> 
					</td>
					<td>
						<select name="city" class="city" lay-verify="" lay-filter="citys">
						  <option value="">城市</option>
						</select> 
					</td>
					<td>
						<select name="Area" class="Area" id="quyu" lay-verify="" lay-filter="Areas">
						  <option value="">区域</option>
						</select> 
					</td>
				</tr>
			</tbody>
		</table>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">是否上架</label>
      	<div class="layui-input-block">
     		<select name="isPut" id="isPut">
			  <option value="2">全部</option>
			  <option value="0">否</option>
			  <option value="1">是</option>
			</select> 
		</div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="formtest"><i class="layui-icon">&#xe615;</i> 搜索</button>
        <button type="reset" id="resets" class="layui-btn layui-btn-primary">重置</button>
      </div>
    </div>
  </form>

</script>

<script>
	let downs = document.querySelector(".downs");
	
  layui.config({
    base: '/src/js/'
  }).use(['jquery', 'mockjs', 'table', 'sidebar', 'form'], function () {
    var $ = layui.jquery,
      layer = layui.layer,
      table = layui.table,
      sidebar = layui.sidebar,
      form = layui.form;
    // 注入mock
    layui.mockjs.inject({
      'POST /demo/table/user': {
        code: 0,
        msg: "xxx",
        count: 1000,
        'data|20': [{
          'id|+1': 1,
          username: '@name',
          sex: '@boolean',
          city: '@city',
          sign: '@csentence',
          experience: '@integer',
          score: '@integer',
          classify: '@word',
          wealth: '@integer',
          auth: '@boolean'
        }]
      }
    });
    //第一个实例
    table.render({
      method: 'post',
      // size: 'sm',
      limit: 10,
      limits: [10,20,30],
      contentType: 'application/json',
      elem: '#test',
      id:'test',
      height: 'full-235',
      url: 'https://xnsmb.xnsoft.net.cn/api/Filtrate_Xn_Website', //数据接口
      page: true, //开启分页
      parseData: function(res){
      	return {
      		'code':0,
      		'count':res.TotalCount,
      		"data":res._Data
      	};
      },
      request: {
		    pageName: 'CurrentPage' //页码的参数名称，默认：page
		    ,limitName: 'PageSize' //每页数据量的参数名，默认：limit
		  },
		  where: {
//				"MemLoginId": "",
//			  "MemberName": "",
//			  "MemberMobile": "",
//			  "CompanyAreaCode": "",	
			  "IsAudit": 2,
      },
      cols: [
        [ //表头
          {
            type: 'checkbox',
//          width: 120,
            sort: true,
            align: 'center',
            fixed: 'left'
          }, {
            field: 'MemLoginId',
            title: '会员ID',
            align: 'center',
//          width: 230
          }, {
            field: 'MemberName',
            title: '会员名称',
            align: 'center',
//          width: 230
          }, {
            field: 'MemberMobile',
            title: '会员手机号',
            align: 'center',
//          width: 230
          }, {
            field: 'WWW',
            title: '网址',
            align: 'center',
//          width: 250
          }, {
            field: 'CompanyArea',
            title: '地址',
            align: 'center',
//          width: 230
          }, {
            field: 'IsAudit',
            title: '上下架状态',
            align: 'center',
            templet:function(d){
            	if(d.IsAudit==0){
            		return '<span>下架</span>'
            	}else if(d.IsAudit==1){
            		return '<span>上架</span>'
            	}
            }
//          width: 230
          }, {
            fixed: 'right',
//          width: 200,
            align: 'center',
            toolbar: '#bartest'
          }
        ]
      ]
    });

    $('#search_hash').on('click', function () {
      var that = this;
      // console.log($('#search_tpl_hash').html());
      sidebar.render({
        elem: that,
        content: $('#search_tpl_hash').html(),
        title: '搜索',
        shade: true,
        // shadeClose:false,
        // direction: 'left'
        // dynamicRender: false,
        // url: 'views/member/all/search.html',
        width: '500px', //可以设置百分比和px
        done: function () {
        	let province = document.querySelector(".province");
        	let city = document.querySelector(".city");
        	let Areas = document.querySelector(".Area");
        	let memLev = document.querySelector(".memLev");
        	let proArr = [];
        	let ciArr = [];
          let areaCode = "";
          
           $("#resets").click(function(){
          	console.log(1)
          	areaCode = '';
          	memLevCode = '';
          })
          
          console.log('ccc');
          form.render();
          $.ajax({//异步请求返回给后台
		    	  url:'https://xnsmb.xnsoft.net.cn/api/GetXn_DispatchRegion',
		    	  type:'get',
		    	  data:{FatherId:'0'},
		    	  dataType:'json',
		    	  beforeSend: function(request) {
			            
			            request.setRequestHeader("Authorization", 'bearer ' + localStorage.getItem("token"));
			        },
		    	  success:function(data){
		    		  //这里获取到数据执行显示
//		    		  console.log("地址data",data)
		    		  proArr = [...data]
		    		  console.log("地址data",proArr)
							let p = document.createElement('option');
							p.value='';
							p.innerText="省份";
		    		  data.forEach((el,index)=>{
						$(".province").append("<option value='"+el.ID+"'>"+el.Name+"</option>");
		    		  	
		    		  })
		    		  renderForm();
		    	  }
		    	  
		      });
		      
		      form.on('select(provinces)', function(data){
		      	$(".city").empty();
//		      			console.log("data.value",data.value)
		      			proArr.forEach((el,index)=>{
		      				if(el.ID==data.value){
		      					areaCode=el.Code;
		      				}
		      			})
		      			if(data.value==""){
		      				areaCode="";
		      			}
		      			console.log("areaCode",areaCode);
						cityCode = data;
			//			console.log("seFrist",seFrist)
//					  console.log(data.value);
					  $.ajax({//异步请求返回给后台
					    	  url:'https://xnsmb.xnsoft.net.cn/api/GetXn_DispatchRegion',
					    	  type:'get',
					    	  data:{FatherId:data.value},
					    	  dataType:'json',
					    	  beforeSend: function(request) {
			            
			            request.setRequestHeader("Authorization", 'bearer ' + localStorage.getItem("token"));
			        },
					    	  success:function(data){
					    	  	ciArr = [...data];
					    		  //这里获取到数据执行显示
					    		  console.log(data)
										$(".city").append("<option value=''>城市</option>");
					    		  data.forEach((el,index)=>{
					    		  	$(".city").append("<option value='"+el.ID+"'>"+el.Name+"</option>");
					    		  })
					    		  renderForm();
					    		  
					    	  }
					    	  
					      });
					});   
					
					form.on('select(citys)', function(data){
						$(".Area").empty();
						let _city = data.value;
						if(data.value==""){
		      				areaCode=areaCode.substr(0,3);
		      			}
						console.log("data.ID",data.value)
//						AreaCode = data;
			//			console.log("seFrist",seFrist)
//					  console.log(data.value);
					  $.ajax({//异步请求返回给后台
					    	  url:'https://xnsmb.xnsoft.net.cn/api/GetXn_DispatchRegion',
					    	  type:'get',
					    	  data:{FatherId:data.value},
					    	  dataType:'json',
					    	  beforeSend: function(request) {
			            
			            request.setRequestHeader("Authorization", 'bearer ' + localStorage.getItem("token"));
			        },
					    	  success:function(data){
					    	  	
					    		  //这里获取到数据执行显示
//					    		  console.log("ciArr",ciArr)
					    		  ciArr.forEach((el,index)=>{
					    		  	if(el.ID==_city){
					    		  		areaCode=el.Code
					    		  	}
					    		  })
										$(".Area").append("<option value=''>区域</option>");
					    		  data.forEach((el,index)=>{
					    		  	$("#quyu").append("<option value='"+el.Code+"'>"+el.Name+"</option>");
					    		  })
					    		  renderForm();
					    		  
					    	  }
					    	  
					      });
					}); 
					
					form.on('select(Areas)', function(data){
						if(data.value!=""){
							areaCode = $("#quyu option:selected").val();
						}else{
							areaCode=areaCode.substr(0,6);
						}
					})
					
					function renderForm(){
					  layui.use('form', function(){	
					   var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加()
					   form.render();
					  });
					}

          //监听提交
          form.on('submit(formtest)', function (data) {
            // layer.msg(JSON.stringify(data.field));
            table.reload('test', {
              where: {
              	  "MemLoginId": $("#memId").val(),
				  "MemberName": $("#memName").val(),
//				  "MemberMobile": "sample string 3",
				  "CompanyAreaCode": areaCode,
				  "IsAudit": $("#isPut option:selected").val()
              }
            });
            return false;
          });
        }
      });
    });
  });
</script>



<script type="text/javascript">
	let batchDel = document.querySelector(".batchDel");
	let downs = document.querySelector(".downs");
	let checkedArr = [];
	let objArr = [];	
	
	layui.use(['jquery', 'mockjs', 'table', 'sidebar', 'form'], function () {
    var $ = layui.jquery,
      layer = layui.layer,
      table = layui.table,
      sidebar = layui.sidebar,
      form = layui.form;
      
//    table.on('checkbox(test)', function(obj){
////		  console.log("obj.checked",obj.checked); //当前是否选中状态
////		  console.log("obj.data",obj.data); //选中行的相关数据
////		  console.log("obj.type",obj.type); //如果触发的是全选，则为：all，如果触发的是单选，则为：one
//			console.log(obj.data)
//			if(obj.type=="one"){
//				if(obj.checked){
//					objArr.push(obj)
//					checkedArr.push(obj.data.Guid)
//					console.log(objArr)
//				}else if(!obj.checked){
//					objArr.splice(objArr.indexOf(obj.data),1)
//					checkedArr.splice(checkedArr.indexOf(obj.data.Guid),1)
//					console.log(objArr)
//				}
//			}
//		
//		});

table.on('checkbox(test)', function(obj){
			var checkStatus = table.checkStatus('test');
			let temp = [];
			let tempObj = [];
			checkStatus.data.forEach((el,index)=>{
				temp.push(el.Guid);
			})
			checkedArr = temp;
			console.log(temp)
		});
    
//  "#/layui/addFenhui?id="
    table.on('tool(test)',function(obj){
    	toolHandel("#/layui/editWeb?id=","Admin_Xn_Website/",obj);
    })
    
    downs.addEventListener("click",function(){
    	if(checkedArr.length!=0){
    		layer.confirm('确认下架？', function(index){
	    		layer.close(index);	
	    		checkedArr.forEach((el,index)=>{
	    			DBHelper.Get("Admin_Xn_Website?id="+el,function(data){
	    				console.log(data)
	    				let _obj = data;
	    				_obj.IsAudit=0;
	    				DBHelper.Put("Admin_Xn_Website?id="+el,_obj,function(data){
	    					console.log(data)
//	    					renderForm();
	    					table.reload('test', {});
//							window.location.reload();
	    				},function(data){
	    					console.log(data)
	    				})
//	    				renderForm();
	    				table.reload('test', {});
//	    				window.location.reload();
	    			},function(data){
	    				console.log(data)
	    			})
	    		})
//	    		table.reload('test', {});
//				window.location.reload();
				
	    	})
    	}else if(checkedArr.length==0){
			layer.alert("请选择至少一个选项")
		}
    	
    })
    
//  批量删除
//  batchDel.addEventListener("click",function(){
//  	batDel("Admin_Xn_Website/",checkedArr,objArr)
//  	
//  })
    
     batchDel.addEventListener("click",function(){
     	if(checkedArr.length!=0){
     		layer.confirm('确认删除？', function(index){
					layer.close(index);	
					console.log("checkedArr",checkedArr)
					DBHelper.Delete("Admin_Xn_Website",checkedArr,function(data){
				      	console.log(data)
				      },function(data){
				      	table.reload('test', {});
				      	console.log(data)
				      })
					
		    });
     	}else if(checkedArr.length==0){
			layer.alert("请选择至少一个选项")
		}
			
			
    })
      
    })
	
	
    //强制刷新
//  var a = window.name
//  if(a == ''){
//  	window.name = "reloded"
//  	location.reload()
//  }else{
//  	window.name=""
//  }
	
</script>

<style scoped>
	.layui-fluid{
		background-color: #FFFFFF;
	}
		.webManInfo-table tr>th{
			text-align: center;
		}
		.webManInfo-table tr>td{
			text-align: center;
		}
      	.block{
      		display: block;
      	}
      	.webManTop-btn{
      		width: 100%;
      		text-align: center;
      		margin-bottom: 30px;
      	}
      	.pupoInfo{
      		margin-top: 20px;
      	}
      	.webManTop-btn button{
      		display: inline-block;
      		width: 200px;
      		border-radius: 5px;
      	}
      	.title{
      		margin-left: 30px;
      		margin-top: 30px;
      	}
      	.save-warp{
      		width: 100%;
      		text-align: center;
      		margin-top: 20px;
      	}
      	.save-warp button{
      		display: inline-block;
      		width: 160px;
      	}
      	.webMan-top{
      		display: flex;
      		justify-content: space-between;
      		margin-top: 30px;
      		margin-bottom: 30px;
      	}
      	.webMan-table{
      		background-color: rgba(0,0,0,0);
      	}
      	
      	
      </style>